<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of renumber</title>
  <meta name="keywords" content="renumber">
  <meta name="description" content="renumber the vertices of a graph">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2003 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="../index.html">matgraph</a> &gt; <a href="index.html">@graph</a> &gt; renumber.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for matgraph/@graph&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>renumber
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>renumber the vertices of a graph</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function renumber(g,perm) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment"> renumber the vertices of a graph
 renumber(g,perm) --- renumber the vertices of a graph accoring to a
 permutation
 renumber(p,part) --- renumber vertices according to a partition.

 perm should be a permutation of 1 through n
 the graph's vertices are permutated so that the old vertex 1 is now
 vertex perm(1), etc.
 Note: perm may be either an array containing the permutation or a
 permutation object. 

 part should be a partition of [n]. We renumber so vertices in the same
 block of the partition are consecutive.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="embed.html" class="code" title="function embed(g,xy)">embed</a>	embed --- create an embedding for a graph</li><li><a href="getxy.html" class="code" title="function z = getxy(g)">getxy</a>	getxy(g) --- give g's embedding (or [] if g doesn't have one)</li><li><a href="hasxy.html" class="code" title="function yn = hasxy(g)">hasxy</a>	hasxy(g) --- determine if an embedding has been created for g</li><li><a href="is_labeled.html" class="code" title="function yn = is_labeled(g)">is_labeled</a>	is_labeled(g) --- determine if there are labels on vertices.</li><li><a href="make_logical.html" class="code" title="function make_logical(g)">make_logical</a>	make_logical(g) --- ensure that the internal storage for g's matrix is a</li><li><a href="nv.html" class="code" title="function n = nv(g)">nv</a>	nv(g) --- number of vertices in g</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="interval_graph.html" class="code" title="function interval_graph(g,ilist)">interval_graph</a>	interval_graph(g,ilist) --- create an interval graph</li><li><a href="iso.html" class="code" title="function [yn,p] = iso(g,h,options)">iso</a>	[yn,p] = iso(g,h,options) --- is g isomorphic to h?</li><li><a href="random_tree.html" class="code" title="function random_tree(t,n)">random_tree</a>	random_tree(t,n) --- overwrite t with a random tree on n vertices</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="#_sub1" class="code">function list = partition2list(p)</a></li></ul>
<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function renumber(g,perm)</a>
0002 <span class="comment">% renumber the vertices of a graph</span>
0003 <span class="comment">% renumber(g,perm) --- renumber the vertices of a graph accoring to a</span>
0004 <span class="comment">% permutation</span>
0005 <span class="comment">% renumber(p,part) --- renumber vertices according to a partition.</span>
0006 <span class="comment">%</span>
0007 <span class="comment">% perm should be a permutation of 1 through n</span>
0008 <span class="comment">% the graph's vertices are permutated so that the old vertex 1 is now</span>
0009 <span class="comment">% vertex perm(1), etc.</span>
0010 <span class="comment">% Note: perm may be either an array containing the permutation or a</span>
0011 <span class="comment">% permutation object.</span>
0012 <span class="comment">%</span>
0013 <span class="comment">% part should be a partition of [n]. We renumber so vertices in the same</span>
0014 <span class="comment">% block of the partition are consecutive.</span>
0015 
0016 
0017 <span class="keyword">global</span> GRAPH_MAGIC
0018 
0019 n = <a href="nv.html" class="code" title="function n = nv(g)">nv</a>(g);
0020 
0021 <span class="keyword">if</span> isa(perm,<span class="string">'partition'</span>)
0022     perm = <a href="#_sub1" class="code" title="subfunction list = partition2list(p)">partition2list</a>(perm);
0023 <span class="keyword">end</span>
0024 
0025 <span class="keyword">if</span> ~isa(perm,<span class="string">'permutation'</span>)
0026     perm = permutation(perm);
0027 <span class="keyword">end</span>
0028 
0029 <span class="keyword">if</span> length(perm) ~= n
0030     error(<span class="string">'Length of permutation does not match size of graph'</span>)
0031 <span class="keyword">end</span>
0032 
0033 perm = inv(perm);
0034 q = array(perm);
0035 
0036 GRAPH_MAGIC.graphs{g.idx}.array = <span class="keyword">...</span>
0037     GRAPH_MAGIC.graphs{g.idx}.array(q,q);
0038 
0039 <a href="make_logical.html" class="code" title="function make_logical(g)">make_logical</a>(g);
0040 
0041 <span class="keyword">if</span> <a href="hasxy.html" class="code" title="function yn = hasxy(g)">hasxy</a>(g)
0042     xy = <a href="getxy.html" class="code" title="function z = getxy(g)">getxy</a>(g);
0043     xy = xy(q,:);
0044     <a href="embed.html" class="code" title="function embed(g,xy)">embed</a>(g,xy);
0045 <span class="keyword">end</span>
0046 
0047 <span class="keyword">if</span> <a href="is_labeled.html" class="code" title="function yn = is_labeled(g)">is_labeled</a>(g)
0048     tmp = cell(n,1);
0049     <span class="keyword">for</span> k=1:n
0050         tmp{k} = GRAPH_MAGIC.graphs{g.idx}.labels{perm(k)};
0051     <span class="keyword">end</span>
0052     GRAPH_MAGIC.graphs{g.idx}.labels = tmp;
0053 <span class="keyword">end</span>
0054 
0055 
0056 <a name="_sub1" href="#_subfunctions" class="code">function list = partition2list(p)</a>
0057 pp = parts(p);
0058 list = [];
0059 <span class="keyword">for</span> k=1:np(p)
0060     list = [list, pp{k}];
0061 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Fri 30-Apr-2010 07:51:16 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/">m2html</a></strong> &copy; 2003</address>
</body>
</html>